<?php
/**��ݻ���ID���������ͣ���ȡ����������Message��Ϣ��Ȼ��ͨ������Message Key����ȡ�����Message��Ϣ��
 */

class MESSAGE {
	var $sForm_ID  = "";
	var $sCorp_CD  = "";
	var $sLanguage = "";
	var $sKey      = "";
	var $sMessage  = "";
	var $aMessage  = array();
	
	//construct method
	function MESSAGE($formid="",$lang="") {
		global $SEC;
		
		$this->sCorp_CD  = $SEC->corp_cd;
		$this->sForm_ID  = $formid;
		$this->sLanguage = $lang;
		
		if ($formid!="" && $lang!="") $this->_getMessageList($formid,$lang);
	}
	
	//set/get Form_ID property
	function setFormID($formid) {
		$this->sForm_ID = $formid;
		if ($this->sForm_ID!="" && $this->sLanguage!="") 
			$this->_getMessageList($this->sForm_ID,$this->sLanguage);
	}
	function getFormID() {
		return $this->sForm_ID;
	}

	//set/get Language property
	function setLanguage($lang) {
		$this->sLanguage = $lang;
		if ($this->sForm_ID!="" && $this->sLanguage!="") 
			$this->_getMessageList($this->sForm_ID,$this->sLanguage);
	}
	function getLanguage() {
		return $this->sLanguage;
	}
	
	//��ȡMessage��ݲ���ӵ�������
	function _getMessageList($formid,$lang) {
		global $DB,$TABLE_MULT_LANG_MESSAGE;
		
		$sql  = "SELECT MESSAGE_KEY,MESSAGE ";
		$sql .= "FROM $TABLE_MULT_LANG_MESSAGE ";
		$sql .= "WHERE VALID_FLG='0' AND FORM_ID='".$this->sForm_ID."' AND LANGUAGE_DIV='".$this->sLanguage."' ";
		if ($this->sCorp_CD!="") $sql .= " AND CORP_CD='".$this->sCorp_CD."'";
		$stmt = $DB->query($sql);
		while (OCIFetchInto($stmt,$row)) {
			$this->aMessage[$row[0]] = $row[1];
		}
		OCIFreeStatement($stmt);
	}
	
	/*get message info by message key
	 *@$sKey Message Key
	 *@$isChangeCode ȷ���Ƿ�ת���Ƿ��ַ�Ĭ����True
	 */
	function getMsg($sKey,$isChangeCode=true) {
		if (isset($this->aMessage[$sKey]))
			return ($isChangeCode?fn_setParam($this->aMessage[$sKey]):$this->aMessage[$sKey]);
		else
			return "<font color=red>!".$this->sForm_ID.".".$sKey."!</font>";
	}

	//unset array
	function close() {
		unset($this->aMessage);
	}
}

?>